package com.jlnk.androidfmc.presenter;

import android.graphics.Bitmap;

import com.jlnk.androidfmc.entity.Product;
import com.jlnk.androidfmc.model.ReleaseModel;
import com.jlnk.androidfmc.view.ReleaseView;

public class ReleasePresenter {
    private ReleaseView view;
    private ReleaseModel model;

    // 修改构造函数以接收 ReleaseView 实例
    public ReleasePresenter(ReleaseView view) {
        this.view = view;
        // 使用 ReleaseView 的 getContext() 方法来初始化 ReleaseModel
        this.model = new ReleaseModel(view.getContext());
    }

    // 处理发布商品的逻辑
    public void releaseItem(Product product) {
        view.showLoading(); // 显示加载指示器
        model.releaseItem(product, new ReleaseModel.ReleaseItemCallback() {
            @Override
            public void onSuccess() {
                view.hideLoading(); // 隐藏加载指示器
                view.showReleaseSuccess(); // 显示发布成功的提示
            }

            @Override
            public void onFailure(String errorMessage) {
                view.hideLoading(); // 隐藏加载指示器
                view.showReleaseError(errorMessage); // 显示错误信息
            }
        });
    }

    // 新增处理图片选择的逻辑
    public void pickImage() {
        if (view.hasStoragePermission()) {
            view.openImagePicker();
        } else {
            view.requestStoragePermission();
        }
    }
}